import 'package:favorcate/core/viewmodel/favor_view_mode.dart';
import 'package:favorcate/core/viewmodel/filter_view_model.dart';
import 'package:favorcate/core/viewmodel/meal_view_model.dart';
import 'package:provider/provider.dart';

import 'core/router/router.dart';
import 'ui/shared/app_theme.dart';
import 'package:flutter/material.dart';

import 'ui/shared/size_fit.dart';

main() => runApp(MultiProvider(providers: [
      ChangeNotifierProvider(create: (ctx) => ZSFilterViewModel()),
      // ChangeNotifierProvider(create: (ctx) => ZSMealViewModel()),
      ChangeNotifierProxyProvider<ZSFilterViewModel, ZSMealViewModel>(
        create: (ctx) => ZSMealViewModel(),
        update: (ctx, filterVM, mealVM) {
          mealVM!.updateFilters(filterVM);
          return mealVM;
        },
      ),
      // ChangeNotifierProvider(create: (ctx) => ZSFavorViewModel()),
      ChangeNotifierProxyProvider<ZSFilterViewModel, ZSFavorViewModel>(
        create: (ctx) => ZSFavorViewModel(),
        update: (ctx, filterVM, favorVM) {
          favorVM!.updateFilters(filterVM);
          return favorVM;
        },
      ),
    ], child: MyApp()));

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //对SizeFit进行初始化
    ZSSizeFit.initialize();

    return MaterialApp(
      title: '美食广场',
      //主题
      theme: ZSAppTheme.normalTheme,
      debugShowCheckedModeBanner: false,
      //路由
      initialRoute: ZSRouter.initialRoute,
      routes: ZSRouter.routes,
      onGenerateRoute: ZSRouter.generateRoute,
      onUnknownRoute: ZSRouter.unknownRoute,
    );
  }
}
